//
//  BeautifulViewController.m
//  Dsgfds
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 胡泉. All rights reserved.
//

#import "BeautifulViewController.h"
#import "BeautifulTableViewCell.h"
#import "PKRequestManager.h"
#import "BeautifulModel.h"
@interface BeautifulViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *contentTableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation BeautifulViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.contentTableView.delegate = self;
    self.contentTableView.dataSource = self;
   
    self.contentTableView.rowHeight = (SCREEN_WIDTH - 20) * 540 / 425;
    UINib *nib = [UINib nibWithNibName:@"BeautifulTableViewCell" bundle:nil];
    [self.contentTableView registerNib:nib forCellReuseIdentifier:@"Bcell"];
    self.dataArray = [NSMutableArray array];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)configureData
{
    [PKRequestManager PKRequestManagerrequsetWithType:GET URLString:@"http://www.yueduziji.com/a/list/?page_size=10&page=1" ParDIc:nil finish:^(NSData *data) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        for (NSDictionary *inDic in dict[@"data"])
        {
            BeautifulModel *model = [[BeautifulModel alloc] init];
            [model setValuesForKeysWithDictionary:inDic];
            [_dataArray addObject:model];
            
        }
        [self.contentTableView reloadData];
        
    } error:^(NSError *error) {
        NSLog(@"error----%@",[error localizedDescription]);
    }];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BeautifulTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Bcell" forIndexPath:indexPath];
    BeautifulModel *model = _dataArray[indexPath.row];
    NSLog(@"asas");
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
